/*
 * Copyright (c) 2010, 2011
 *	Open Source Technologies Ltd.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the company nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COMPANY AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#ifndef __BLISS64_DEFS_H__
#define __BLISS64_DEFS_H__

#if defined(WIN32) || defined(WIN64)
#define WINDOWS
#endif /* WIN32 || WIN64 */

#if defined WINDOWS

#pragma warning(disable: 4996)

typedef int bool;

#define true  (1)
#define false (0)

#define PATH_MAX 1024

#else /* !WINDOWS */

#include <stdbool.h>

#endif /* !WINDOWS */

#define type_signed(t) (! ((t) 0 < (t) -1))
#define type_min(t) \
	((t) (! type_signed(t) \
	? (t) 0 \
	: ((t) 1 << (sizeof(t) * CHAR_BIT - 1))))
#define type_max(t) \
	((t) (! type_signed (t) \
	? (t) -1 \
	: ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))

#if defined(__cplusplus)
#define	__begin_decls extern "C" {
#define	__end_decls }
#else /* !__cplusplus */
#define	__begin_decls
#define	__end_decls
#endif /* !__cplusplus */

#if defined(__STDC__) || defined(__cplusplus)
#define	__p(proto) proto
#else /* !__STDC__ && !__cplusplus */
#define __p(proto) ()
#endif /* !__STDC__ && !__cplusplus */

#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif /* !min */

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif /* !max */

#define swap(a, b) { \
	a ^= b; \
	b ^= a; \
	a ^= b; \
}

#define is_object(obj, field, magic)      (((obj) != NULL) && ((obj)->field == magic))
#define is_object_dead(obj, field, magic) (((obj) != NULL) && ((obj)->field != magic))
#define is_object_opt(obj, field, magic)  (((obj) == NULL) || ((obj)->field == magic))

#endif /* !__BLISS64_DEFS_H__ */
